//该中间件用于是否存在cookie

//需要cookie验证的路径
const needCookies=[
    {url:'/addStudent',method:'GET'},
    {url:'/students',method:'GET'},
]
module.exports=(req,res,next)=>{
    const apis= needCookies.filter((item)=>{
        return item.url===req.path&&item.method===req.method;
    })
    if(apis.length!==0){
        // console.log(req.cookies);
        //说明需要cookie验证
        if(!req.cookies.name){
            //不存在cookie 
            res.redirect('/login');
            return;
            
        }
        next();
            return;
    }
    next()
}